package com.d0323;
import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class ByteArrayBufferTest {
    static byte[] myBuffer;

    public static void main(String[] args) {
        writerBuffer();
        readerBuffer();
    }

    private static void writerBuffer() {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        try {
            dos.writeInt(100);
            dos.writeDouble(3.14);
            dos.writeUTF("icss");
            dos.close();
            baos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void readerBuffer() {
        ByteArrayInputStream bais = new ByteArrayInputStream(myBuffer);
        DataInputStream dis = new DataInputStream(bais);
        try {
            System.out.println(dis.readInt() + "\t" + dis.readDouble() + "\t" + dis.readUTF());
            dis.close();
            bais.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
